﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CCWin.SkinControl;
using DSAClient.Core;
using DSAClient.Models.Input;
using DSAClient.Models.Output;
using DSAClient.Utils;

namespace DSAClient
{
    public partial class Main : BaseForm
    {
        Point mouseOff;//鼠标移动位置变量
        bool leftFlag;//标记是否为左键
        SkinWaterTextBox swtwwh;
        SkinWaterTextBox swtddh;

        public Main()
        {
            InitializeComponent();

            swtwwh = new SkinWaterTextBox();
            panel1.Controls.Add(swtwwh);
            swtwwh.WaterText = "旺旺号";
            swtwwh.WaterColor = Color.FromArgb(127, 127, 127);
            swtwwh.AutoSize = false;
            swtwwh.Font = new Font(swtwwh.Font.Name, 19);
            swtwwh.Height = 34;
            swtwwh.BackColor = Color.White;
            swtwwh.Location = new Point(142, 82);
            swtwwh.Size = new Size(217, 28);
            
            swtwwh.BorderStyle = BorderStyle.None;
            swtwwh.Text = "";

            swtddh = new SkinWaterTextBox();
            panel1.Controls.Add(swtddh);
            swtddh.WaterText = "订单号";
            swtddh.WaterColor = Color.FromArgb(127, 127, 127);
            swtddh.AutoSize = false;
            swtddh.Font = new Font(swtwwh.Font.Name, 19);
            swtddh.Height = 34;
            swtddh.BackColor = Color.White;
            swtddh.Location = new Point(142, 152);
            swtddh.Size = new Size(217, 28);
            swtddh.BorderStyle = BorderStyle.None;
            swtddh.Text = "";

            


        }

        private void titlePanel_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Cursor = Cursors.Hand;
                mouseOff = new Point(-e.X, -e.Y); //得到变量的值
                leftFlag = true;                  //点击左键按下时标注为true;
            }

        }

        private void titlePanel_MouseMove(object sender, MouseEventArgs e)
        {
            if (leftFlag)
            {
                Point mouseSet = Control.MousePosition;
                mouseSet.Offset(mouseOff.X, mouseOff.Y);  //设置移动后的位置
                Location = mouseSet;
            }
        }

        private void titlePanel_MouseUp(object sender, MouseEventArgs e)
        {
            if (leftFlag)
            {
                leftFlag = false;//释放鼠标后标注为false;
                this.Cursor = Cursors.Default;
            }
        }

        private void skinButton4_Click(object sender, EventArgs e)
        {
            lbmsg.Visible = false;
            if (swtddh.Text != "" && swtwwh.Text != "")
            {
                var result = Api.GetTaobaoOrder(new TaobaoOrderGetPara() { no = swtddh.Text, ww = System.Web.HttpUtility.UrlEncode(swtwwh.Text) });
                if (!result.ok)
                {
                    lbmsg.Text = result.msg;
                    lbmsg.Visible = true;
                }
                else
                {
                    GridForm gridForm = new GridForm(result.data);
                    gridForm.Show();
                    this.Hide();

                    //ImageForm imageForm = new ImageForm();
                    //imageForm.Show();
                    //imageForm.Hide();
                }
            }
            else
            {
                lbmsg.Text = "旺旺号和订单号必须填写";
                lbmsg.Visible = true;
            }
            //MessageBox.Show(JsonHelper.SerializeObject(result));
            //GridForm gridForm = new GridForm();
            //gridForm.Show();
            //this.Hide();
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("notepad.exe", "ttt");
        }
    }
}
